﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace WPFNote.Utilities.Converters {
    public class  DateToStringConverter: IValueConverter{
        
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            try {
                if (value != null && DateTime.TryParse(value.ToString(), out var result)) {
                    return result.ToString("yyyy-MM-dd HH:mm:ss");
                }
                return string.Empty;
            } catch {
                return string.Empty;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            try {
                if (value != null && DateTime.TryParse(value.ToString(), out var result)) {
                    return result;
                }
                return DateTime.MinValue;
            } catch {
                return DateTime.MinValue;
            }
        }
    }
}